`
https://leetcode.cn/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/
`

/**
 * @param {number[]} arr
 * @param {number} k
 * @param {number} threshold
 * @return {number}
 */
var numOfSubarrays = function (arr, k, threshold) {
  const n = arr.length
  let res = 0
  let sum = 0
  let left = 0, right = 0

  // 维护一个长度为 k 的滑动窗口即可
  while (right < n) {
    const n1 = arr[right++]
    sum += n1

    const len = right - left
    if (len >= k) {
      // 在窗口长度为 k 的时候更新答案
      if (sum / len >= threshold) res++
      const n2 = arr[left++]
      sum -= n2
    }
  }

  return res
};